import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Wall here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Wall extends Trap
{
    private boolean goingDown;
    private int minY;
    private int maxY;
    
    public Wall(int x,int del,int iniD,int min,int max,int type)
    {
        super(x,del,iniD);
        
        goingDown=true;
        minY=min;
        maxY=max;
        damage=30;
        
        switch(type)
        {
            case 1:     setImage(new GreenfootImage("wall_jungle.png"));
                        break;
            default:    setImage(new GreenfootImage("wall.png"));
                        break;
        }
        
        GreenfootImage image=getImage();
        image.setTransparency(0);
        setImage(image);
    }
    
    public void act() 
    {
        timer.tick();
        activeTimer.tick();
        
        GameWorld world=(GameWorld)getWorld();
        
        setLocation(world.getScrollx()+360+posX,getY());
        
        if(active==true || !activeTimer.wait(initialDelay))     
        activeImage();
        if(active==false)
        return;
        
        
        
        if(goingDown==true)
        {
            if(getY()+getImage().getHeight()/2>maxY)
            {
                if(!timer.wait(delay))
                goingDown=false;
            }else
            setLocation(getX(),getY()+1);
        }
        else
        {
            if(getY()+getImage().getHeight()/2<minY)
            {
                if(!timer.wait(delay))
                goingDown=true;
            }else
            setLocation(getX(),getY()-1);
        }
        
        Player player=getPlayer();
        
        if(goingDown && isTouchingPlayer())
        player.getHurt(damage);
    }    
    
    public boolean isPlayerDown()
    {
        for(int i=2;i<getImage().getWidth()-2;i++)
            if(getOneObjectAtOffset(i,getImage().getHeight()/2,Player.class)!=null && isTouchingPlayer())
            return(true);
        
        return(false);
    }
}
